<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMenuStepTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up() {
     // 主菜单数据表
        Schema::create('menus', function (Blueprint $table) {
            // 表结构
            $table->increments('id')->comment('自增ID');
            $table->string('code')->unique()->comment('主菜单编号');
            $table->string('name')->comment('主菜单名称');
            $table->string('parent_code')->default('0')->comment('主菜单父类编号');
            $table->string('iconfont')->comment('文字图标');
            $table->integer('show_level')->default(0)->comment('显示级别 正序');
            $table->string('slug')->comment('权限');
            $table->softDeletes();
            $table->timestamps();
        });

        // 子菜单数据表
        Schema::create('submenus', function (Blueprint $table) {
            // 表结构
            $table->increments('id')->comment('自增ID');
            $table->string('code')->unique()->comment('子菜单编号');
            $table->string('name')->comment('子菜单名称');
            $table->string('parent_code')->default('0')->comment('子菜单父类编号');
            $table->string('menu_code')->comment('主菜单编号');
            $table->string('iconfont')->comment('文字图标');
            $table->integer('show_level')->default(0)->comment('显示级别 正序');
            $table->string('url')->comment('功能链接');
            $table->string('slug')->comment('权限');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('menu_code')->references('code')->on('menus')
                ->onDelete('restrict')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('submenus');
        Schema::dropIfExists('menus');
    }
}
